package com.kiln.juxingqs.adapter

import androidx.recyclerview.widget.DiffUtil
import client.global.commlib.base.BasePagingAdapter
import client.global.commlib.base.PagingViewHoder
import com.kiln.juxingqs.R
import com.kiln.juxingqs.api.bean.GetBathRet
import com.kiln.juxingqs.databinding.LayoutPagingbathitemBinding

class GetPagingBathRetAdapter :
    BasePagingAdapter<GetBathRet.Bath>(object : DiffUtil.ItemCallback<GetBathRet.Bath>() {
        override fun areItemsTheSame(
            oldItem: GetBathRet.Bath,
            newItem: GetBathRet.Bath
        ): Boolean {
            return oldItem.bath_id == newItem.bath_id
        }

        override fun areContentsTheSame(
            oldItem: GetBathRet.Bath,
            newItem: GetBathRet.Bath
        ): Boolean {
            return oldItem == newItem
        }
    }) {

    var ok: ((b: GetBathRet.Bath) -> Unit)? = null

    fun okClick(b: GetBathRet.Bath) {
        ok?.invoke(
            b
        )
    }

    override fun bindItem(holder: PagingViewHoder, t: Any) {
        val binding = holder.binding as LayoutPagingbathitemBinding
        val bean = t as GetBathRet.Bath
        binding.bean = bean
        binding.event = this
        val time = bean.create_time.substring(
            5,
            bean.create_time.length - 3

        )
        binding.time = time

        if (!bean.status_str.isNullOrEmpty()) {
            binding.type = bean.status_str
        } else
            when (bean.t_type) {
                0 -> {
                    binding.type = "交易票"
                }
                1 -> {
                    binding.type = "冻结票"
                }
                2 -> {
                    binding.type = "释放票"
                }
            }
    }

    override fun getItemLayout(): Int {
        return R.layout.layout_pagingbathitem
    }
}